Fix header compressed size check by checking against an aligned size #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #4.
It seems the size check would often fail on some fonts as the size of the compressed section provided by the header might not take into account the 4-byte alignment of the section. The comparison is now done between the actual consumed input size after processing the compressed section (the input buffer is consumed until after the potential padding bytes), and the size reported by the header aligned to the next multiple of 4.
The spec seems to indicate that the compressed section should always be padded to 4 byte alignment if followed by an extended metadata block or a private data block, but I'm not totally sure if it enforces this alignment when the compressed block is the last one. However on the font files I checked, the compressed block was always padded even if nothing followed.
This PR also add some derives on the public error type that might be useful to the crate consumers.
I tested with a few fonts (notably those listed in #4) and this seems to be working properly.